﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using 学生册成绩管理系统.BLL;
using 学生册成绩管理系统.DAL;
using 学生册成绩管理系统.Models;
using 学生册成绩管理系统.MVVM;

namespace 学生册成绩管理系统.ViewModels
{
    public class RegisterViewModel
    {

        private Student student = new Student();

		public Student Student
		{
			get { return student; }
			set { student = value; }
		}

        public bool Boy { get; set; } = true;
        public bool Girl { get; set; } = false;


        public ICommand RegisterCommand { get; }
		public RegisterViewModel()
		{
			RegisterCommand = new RelayCommand(Register);
		}

		// 注册新用户
        private void Register()
        {
            student.Role = 1;

            if (Boy == true)
            {
                student.Sex = true;
            }
            else
            {
                student.Sex = false;
            }
            student.InsertDate = DateTime.Now;

            // 写入数据库
            //string sql = "Insert Into Student() Values ()";
            //SqlHelper sqlHelper = new SqlHelper();
            //int count = sqlHelper.ExecuteNonQuery(sql,null);
            //if (count > 0)
            //{
            //    MessageBox.Show($"恭喜{student.Name}，注册成功！");
            //}
            StudentService studentService = new StudentService();
            int count = studentService.Insert(Student);

            if (count == -1)
            {
                MessageBox.Show($"必填项不能为空");
            }
            else if (count == 0)
            {
                MessageBox.Show($"注册失败");
            }
            else
            {
                MessageBox.Show($"{Student.Name},恭喜你注册成功");
            }
        }
    }
}
